<?php //pack11class

class PagesManager {

    private static $pagesDone=false;
    private static $pagesByID=array();
    private static $pagesByName=array();

    private static function init() {
        array_push(Tracer::$traceFrom,__CLASS__);
        $pagesData=MySQLGet::process("Select * from ".MySQL::TABLE_PAGES.";");
        if(!$pagesData) return false;
        foreach($pagesData as $row) {
            $page=new Page;
            $page->setDataFromSQL($row);
            self::$pagesByID[$page->id]=$page;
            self::$pagesByName[$page->system]=$page;
        }
        self::$pagesDone=true;
    }

    public static function getPage($id) {
        if(!self::$pagesDone) self::init();
        if(is_numeric($id)) {
            if(array_key_exists($id, self::$pagesByID)) {
                return self::$pagesByID[$id];
            } else {
                return false;
            }
        } else {
            if(array_key_exists($id, self::$pagesByName)) {
                return self::$pagesByName[$id];
            } else {
                return false;
            }
        }
    }
}
?>
